﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TierService;
using TierApplication;
using System.Data;
using DevExpress.Web.ASPxGridView;
using System.Web.Services;

public partial class System_Product_ProductImpList_Audited : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindData();
        }
        else if (gridSearchResult.IsCallback && Page.IsPostBack)
        {
            System.Data.DataTable dt = (DataTable)ViewState["data"];
            gridSearchResult.DataSource = dt;
            gridSearchResult.DataBind();
        }


    }

    #region BindData
    private void BindData()
    {
        #region 权限检查

        #endregion

        string IMPBATCHNO = txtIMPBATCHNO.Text.Trim();
        string IMPDATE = txtIMPDATE.Text;
        string strWhere = "";
        strWhere += " and a.IMPSTATUS='2'";
        if (IMPBATCHNO != "")
        {
            strWhere += " and (a.IMPBATCHNO like'%" + IMPBATCHNO + "%')";
        }

        if (IMPDATE != "")
        {
            strWhere += " and (TO_CHAR(a.IMPDATE,'YYYYMMDD') ='" + txtIMPDATE.Date.ToString("yyyyMMdd") + "')";
        }

        DataSet ds = T_PRODUCTIMP.GetProductImpList(strWhere);
        gridSearchResult.DataSource = ds.Tables[0];
        gridSearchResult.DataBind();
        ViewState["data"] = ds.Tables[0];
    }
    #endregion

    #region btn_Search

    protected void btnQuery_Click(object sender, EventArgs e)
    {
        BindData();
    }

    protected void btnQuery_CallBack(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
    {
        BindData();
    }



    #endregion

    #region gridView事件
    protected void gridSearchResult_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
    {
        String theID = e.Keys[0].ToString();
        object theValues = this.gridSearchResult.GetRowValuesByKeyValue(theID, new String[] { "IMPBATCHNO" });
        String IMPBATCHNO = theValues.ToString();
        if (!String.IsNullOrEmpty(IMPBATCHNO))
        {
            string ac_impbatchno = IMPBATCHNO;
            string ac_userid = "";
            Int32 ai_result = 0;
            string ac_result = "";
            T_PRODUCTIMP mProductImp = new T_PRODUCTIMP();
            mProductImp.IMP_PRODUCT_IMP_DELETE(ac_impbatchno, ac_userid, ref ai_result, ref ac_result);
            if (ai_result < 0)
            {

            }

            //Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "b", "<script>alert('error');</script>");   
         
            e.Cancel = true;
            this.gridSearchResult.CancelEdit();
            BindData();

        }

    }

    protected void btnRowDeleteCallBack_CallBack(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
    {
        string ac_ImpBatchNo = e.Parameter;
        string ac_userid = "";
        Int32 ai_result = 0;
        string ac_result = "";

        T_PRODUCTIMP mProductImp = new T_PRODUCTIMP();
        mProductImp.IMP_PRODUCT_IMP_DELETE(ac_ImpBatchNo, ac_userid, ref ai_result, ref ac_result);

        if (ai_result == 0)
        {
            e.Result = "ok";
        }
        else
        {
            e.Result = ac_result;

        }
    }


    #endregion

}